<template>
  <view>
    <view class="page">
      <u-search v-model="value" placeholder="请输入搜索关键词" @search="onSearch"></u-search>
      <block>
        <block data-type="template" data-is="imgType" data-attr="classList,goods">
          <view class="navList">
            <view v-for="(item, index) in classList" :key="index"
              :class="(item.check ? 'navList__itemCheck' : 'navList__item') + ' '" :data-mode="item" @tap="chooseCheck">
              <view>{{item.name}}</view>
            </view>
          </view>
          <view v-for="(good, index) in goods" :key="index">
            <act-goods :name="good.name + ' '" :actPrice="good.actPrice" :price="good.price" :img="good.pic"
              :goodId="good.id"></act-goods>
          </view>
        </block>
      </block>
    </view>

    <template name="listType">
      <view>odd</view>
    </template>
  </view>
</template>
<script lang='ts'>
  import {
    Component,
    Vue
  } from 'vue-property-decorator'
  import {
    getGroupGoodsList,
    getGoodClass
  } from "@/api/modules/goods";
  import actGoods from "@/components/act-goods/act-goods.vue";
  @Component({
    components: {
      actGoods
    }
  })
  export default class group extends Vue {
    classList: Array < any >= []
    // 商品数组
    goods: Array < any >= []
    current = 1
    size:number|string = 10
    selectId = ""
    created() {
      this.getAllList();
    }
    /**
     * 获取商品分类
     */
    getAllClass() {
      getGoodClass(0, {}).then(res => {
        res.map((item: {
          check: boolean;
        }) => {
          return (item.check = false);
        });
        res.unshift({
          name: "全部",
          id: 0,
          check: true,
        });
        this.classList = res
      });
    }

    /**
     * 获取商品
     */
    getAllList() {
      const param = {
        current: this.current,
        size: this.size,
        //  showCategoryId: this.data.selectId,
      };
      getGroupGoodsList(param).then((res: {
        list: Array < any >
      }) => {
        const list = res.list;
        list.forEach(item => {
          if (item.skuStocks.list === 1) {
            item.price = item.originalPrice;
            item.actPrice = item.price;
          } else {
            item.price = Math.min.apply(
              Math,
              item.skuStocks.map(o => {
                return o.originalPrice;
              }),
            );
            item.actPrice = Math.max.apply(
              Math,
              item.skuStocks.map(o => {
                return o.price;
              }),
            );
          }
        });
        // this.goods= res.list
        this.goods = list
      });
    }
  }
</script>
<style scoped>
</style>